#!/usr/bin/env python3
# Copyright (C) 2023 Checkmk GmbH - License: GNU General Public License v2
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.

from collections.abc import Mapping

import pytest

from cmk.agent_based.v2 import CheckResult, Metric, Result, Service, State
from cmk.plugins.collection.agent_based.cisco_qos import (
    check_cisco_qos_,
    discover_cisco_qos,
    parse_cisco_qos,
    Section,
)


@pytest.fixture(name="section", scope="module")
def fixture_section() -> Section:
    return parse_cisco_qos(
        [
            [
                ["161650", "10103"],
                ["161696", "10106"],
                ["461883654", "20715"],
                ["461883702", "20716"],
                ["1261575062", "20509"],
                ["1530016262", "20513"],
                ["1530016278", "20512"],
                ["1530016294", "20511"],
                ["1530016310", "20510"],
                ["1530016324", "20517"],
                ["1530016326", "20517"],
                ["1530016340", "20516"],
                ["1530016342", "20516"],
                ["1530016372", "20514"],
                ["1530016374", "20514"],
                ["1530016420", "20519"],
                ["1530016422", "20519"],
                ["1530016438", "20518"],
                ["4219966596", "20737"],
                ["4219966598", "20737"],
                ["4219966614", "20736"],
            ],
            [
                ["6243696", "1Mbit"],
                ["27957568", "100Mbit"],
                ["67784700", "queue-fix"],
                ["70267388", "140Mbit"],
                ["75456647", "SCH_PRI_40M"],
                ["87743823", "SCH_SHAPE_40M"],
                ["104386316", "SCH_DUMMY"],
                ["110179659", "200Mbit"],
                ["119689584", "50Mbit"],
            ],
            [
                ["1593", "class-default"],
                ["315700052", "SCH_CL-VOIP"],
                ["365823413", "cos-zero"],
                ["376253051", "SCH_CL-OAM"],
            ],
            [
                ["161650.1", "67784700"],
                ["161650.65536", "365823413"],
                ["161650.65537", "596974045"],
                ["161650.65538", "826974748"],
                ["161650.131072", "1593"],
                ["161650.131073", "1594"],
                ["161696.1", "110179659"],
                ["161696.65536", "1593"],
                ["161696.65537", "1594"],
                ["161696.65538", "1723258637"],
                ["461883654.1", "67784700"],
                ["461883654.65536", "365823413"],
                ["461883654.65537", "596974045"],
                ["461883654.65538", "826974748"],
                ["461883654.131072", "1593"],
                ["461883654.131073", "1594"],
                ["461883702.1", "67784700"],
                ["461883702.65536", "365823413"],
                ["461883702.65537", "596974045"],
                ["461883702.65538", "826974748"],
                ["461883702.131072", "1593"],
                ["461883702.131073", "1594"],
                ["1261575062.1", "67784700"],
                ["1261575062.65536", "365823413"],
                ["1261575062.65537", "596974045"],
                ["1261575062.65538", "826974748"],
                ["1261575062.131072", "1593"],
                ["1261575062.131073", "1594"],
                ["1530016262.1", "67784700"],
                ["1530016262.65536", "365823413"],
                ["1530016262.65537", "596974045"],
                ["1530016262.65538", "826974748"],
                ["1530016262.131072", "1593"],
                ["1530016262.131073", "1594"],
                ["1530016278.1", "67784700"],
                ["1530016278.65536", "365823413"],
                ["1530016278.65537", "596974045"],
                ["1530016278.65538", "826974748"],
                ["1530016278.131072", "1593"],
                ["1530016278.131073", "1594"],
                ["1530016294.1", "67784700"],
                ["1530016294.65536", "365823413"],
                ["1530016294.65537", "596974045"],
                ["1530016294.65538", "826974748"],
                ["1530016294.131072", "1593"],
                ["1530016294.131073", "1594"],
                ["1530016310.1", "67784700"],
                ["1530016310.65536", "365823413"],
                ["1530016310.65537", "596974045"],
                ["1530016310.65538", "826974748"],
                ["1530016310.131072", "1593"],
                ["1530016310.131073", "1594"],
                ["1530016324.1", "27957568"],
                ["1530016324.65536", "1593"],
                ["1530016324.65537", "1594"],
                ["1530016324.65538", "1611325018"],
                ["1530016326.1", "67784700"],
                ["1530016326.65536", "365823413"],
                ["1530016326.65537", "596974045"],
                ["1530016326.65538", "826974748"],
                ["1530016326.131072", "1593"],
                ["1530016326.131073", "1594"],
                ["1530016340.1", "119689584"],
                ["1530016340.65536", "1593"],
                ["1530016340.65537", "1594"],
                ["1530016340.65538", "1613719786"],
                ["1530016342.1", "67784700"],
                ["1530016342.65536", "365823413"],
                ["1530016342.65537", "596974045"],
                ["1530016342.65538", "826974748"],
                ["1530016342.131072", "1593"],
                ["1530016342.131073", "1594"],
                ["1530016372.1", "70267388"],
                ["1530016372.65536", "1593"],
                ["1530016372.65537", "1594"],
                ["1530016372.65538", "1687558182"],
                ["1530016374.1", "67784700"],
                ["1530016374.65536", "365823413"],
                ["1530016374.65537", "596974045"],
                ["1530016374.65538", "826974748"],
                ["1530016374.131072", "1593"],
                ["1530016374.131073", "1594"],
                ["1530016420.1", "27957568"],
                ["1530016420.65536", "1593"],
                ["1530016420.65537", "1594"],
                ["1530016420.65538", "1611325018"],
                ["1530016422.1", "67784700"],
                ["1530016422.65536", "365823413"],
                ["1530016422.65537", "596974045"],
                ["1530016422.65538", "826974748"],
                ["1530016422.131072", "1593"],
                ["1530016422.131073", "1594"],
                ["1530016438.1", "67784700"],
                ["1530016438.65536", "365823413"],
                ["1530016438.65537", "596974045"],
                ["1530016438.65538", "826974748"],
                ["1530016438.131072", "1593"],
                ["1530016438.131073", "1594"],
                ["4219966596.1", "104386316"],
                ["4219966596.65536", "1593"],
                ["4219966596.65537", "1594"],
                ["4219966598.1", "87743823"],
                ["4219966598.65536", "1593"],
                ["4219966598.65537", "1594"],
                ["4219966598.65538", "1396371392"],
                ["4219966598.131072", "75456647"],
                ["4219966598.196608", "376253051"],
                ["4219966598.196609", "662125111"],
                ["4219966598.196610", "1696472001"],
                ["4219966598.196611", "891165643"],
                ["4219966598.262144", "315700052"],
                ["4219966598.262145", "553671659"],
                ["4219966598.262146", "1704219270"],
                ["4219966598.262147", "898912908"],
                ["4219966598.327680", "1593"],
                ["4219966598.327681", "1594"],
                ["4219966614.1", "6243696"],
                ["4219966614.65536", "1593"],
                ["4219966614.65537", "1594"],
                ["4219966614.65538", "1620139242"],
            ],
            [
                ["161650.65536", "0"],
                ["161650.131072", "3582942391"],
                ["161696.65536", "3449842085"],
                ["461883654.65536", "2199349605"],
                ["461883654.131072", "841195552"],
                ["461883702.65536", "499818046"],
                ["461883702.131072", "7690"],
                ["1261575062.65536", "2761372241"],
                ["1261575062.131072", "859651962"],
                ["1530016262.65536", "3057234164"],
                ["1530016262.131072", "828240805"],
                ["1530016278.65536", "553983275"],
                ["1530016278.131072", "204578"],
                ["1530016294.65536", "2236240251"],
                ["1530016294.131072", "839651171"],
                ["1530016310.65536", "1901711335"],
                ["1530016310.131072", "183472"],
                ["1530016324.65536", "1430245122"],
                ["1530016326.65536", "0"],
                ["1530016326.131072", "196828812"],
                ["1530016340.65536", "2483955098"],
                ["1530016342.65536", "2189036182"],
                ["1530016342.131072", "21383"],
                ["1530016372.65536", "965940781"],
                ["1530016374.65536", "3736298831"],
                ["1530016374.131072", "964549"],
                ["1530016420.65536", "3658646874"],
                ["1530016422.65536", "0"],
                ["1530016422.131072", "3962125354"],
                ["1530016438.65536", "2217981852"],
                ["1530016438.131072", "793623776"],
                ["4219966596.65536", "17152060"],
                ["4219966598.65536", "1423129141"],
                ["4219966598.196608", "20272062"],
                ["4219966598.262144", "1396857570"],
                ["4219966598.327680", "5999509"],
                ["4219966614.65536", "89010489"],
            ],
            [
                ["161650.65536", "0"],
                ["161650.131072", "0"],
                ["161696.65536", "87506524"],
                ["461883654.65536", "0"],
                ["461883654.131072", "0"],
                ["461883702.65536", "0"],
                ["461883702.131072", "0"],
                ["1261575062.65536", "0"],
                ["1261575062.131072", "0"],
                ["1530016262.65536", "0"],
                ["1530016262.131072", "0"],
                ["1530016278.65536", "0"],
                ["1530016278.131072", "0"],
                ["1530016294.65536", "0"],
                ["1530016294.131072", "0"],
                ["1530016310.65536", "0"],
                ["1530016310.131072", "0"],
                ["1530016324.65536", "0"],
                ["1530016326.65536", "0"],
                ["1530016326.131072", "0"],
                ["1530016340.65536", "3243000529"],
                ["1530016342.65536", "0"],
                ["1530016342.131072", "0"],
                ["1530016372.65536", "227928859"],
                ["1530016374.65536", "0"],
                ["1530016374.131072", "0"],
                ["1530016420.65536", "0"],
                ["1530016422.65536", "0"],
                ["1530016422.131072", "0"],
                ["1530016438.65536", "0"],
                ["1530016438.131072", "0"],
                ["4219966596.65536", "0"],
                ["4219966598.65536", "362009492"],
                ["4219966598.196608", "4048"],
                ["4219966598.262144", "27421708"],
                ["4219966598.327680", "334583736"],
                ["4219966614.65536", "824534482"],
            ],
            [
                ["1", "Vlan1"],
                ["70", "Vlan70"],
                ["75", "Vlan75"],
                ["1790", "Vlan1790"],
                ["10101", "GigabitEthernet0/1"],
                ["10102", "GigabitEthernet0/2"],
                ["10103", "GigabitEthernet0/3"],
                ["10104", "GigabitEthernet0/4"],
                ["10105", "GigabitEthernet0/5"],
                ["10106", "GigabitEthernet0/6"],
                ["10107", "GigabitEthernet0/7"],
                ["10108", "GigabitEthernet0/8"],
                ["10109", "GigabitEthernet0/9"],
                ["10110", "GigabitEthernet0/10"],
                ["10111", "GigabitEthernet0/11"],
                ["10112", "GigabitEthernet0/12"],
                ["10113", "GigabitEthernet0/13"],
                ["10114", "GigabitEthernet0/14"],
                ["10115", "GigabitEthernet0/15"],
                ["10116", "GigabitEthernet0/16"],
                ["10117", "GigabitEthernet0/17"],
                ["10118", "GigabitEthernet0/18"],
                ["10119", "GigabitEthernet0/19"],
                ["10120", "GigabitEthernet0/20"],
                ["10121", "GigabitEthernet0/21"],
                ["10122", "GigabitEthernet0/22"],
                ["10123", "GigabitEthernet0/23"],
                ["10124", "GigabitEthernet0/24"],
                ["10201", "TenGigabitEthernet0/1"],
                ["10202", "TenGigabitEthernet0/2"],
                ["10501", "Null0"],
                ["10502", "GigabitEthernet0"],
                ["20506", "Loopback0"],
                ["20509", "GigabitEthernet0/1.ServiceInstance.5"],
                ["20510", "GigabitEthernet0/1.ServiceInstance.6"],
                ["20511", "GigabitEthernet0/1.ServiceInstance.7"],
                ["20512", "GigabitEthernet0/1.ServiceInstance.8"],
                ["20513", "GigabitEthernet0/1.ServiceInstance.9"],
                ["20514", "GigabitEthernet0/1.ServiceInstance.10"],
                ["20516", "GigabitEthernet0/1.ServiceInstance.12"],
                ["20517", "GigabitEthernet0/1.ServiceInstance.13"],
                ["20518", "GigabitEthernet0/1.ServiceInstance.14"],
                ["20519", "GigabitEthernet0/1.ServiceInstance.15"],
                ["20582", "TenGigabitEthernet0/1-mpls layer"],
                ["20583", "TenGigabitEthernet0/2-mpls layer"],
                ["20715", "GigabitEthernet0/1.ServiceInstance.16"],
                ["20716", "GigabitEthernet0/1.ServiceInstance.17"],
                ["20736", "GigabitEthernet0/1.ServiceInstance.18"],
                ["20737", "GigabitEthernet0/1.ServiceInstance.19"],
            ],
            [
                ["1", "1000000000"],
                ["70", "1000000000"],
                ["75", "1000000000"],
                ["1790", "1000000000"],
                ["10101", "1000000000"],
                ["10102", "1000000000"],
                ["10103", "1000000000"],
                ["10104", "1000000000"],
                ["10105", "1000000000"],
                ["10106", "1000000000"],
                ["10107", "10000000"],
                ["10108", "10000000"],
                ["10109", "10000000"],
                ["10110", "10000000"],
                ["10111", "10000000"],
                ["10112", "10000000"],
                ["10113", "10000000"],
                ["10114", "10000000"],
                ["10115", "10000000"],
                ["10116", "10000000"],
                ["10117", "10000000"],
                ["10118", "10000000"],
                ["10119", "10000000"],
                ["10120", "10000000"],
                ["10121", "10000000"],
                ["10122", "10000000"],
                ["10123", "10000000"],
                ["10124", "100000000"],
                ["10201", "4294967295"],
                ["10202", "4294967295"],
                ["10501", "4294967295"],
                ["10502", "1000000000"],
                ["20506", "4294967295"],
                ["20509", "1000000000"],
                ["20510", "1000000000"],
                ["20511", "1000000000"],
                ["20512", "1000000000"],
                ["20513", "1000000000"],
                ["20514", "1000000000"],
                ["20516", "1000000000"],
                ["20517", "1000000000"],
                ["20518", "1000000000"],
                ["20519", "1000000000"],
                ["20582", "4294967295"],
                ["20583", "4294967295"],
                ["20715", "1000000000"],
                ["20716", "1000000000"],
                ["20736", "1000000000"],
                ["20737", "1000000000"],
            ],
            [
                ["161650.1", "0"],
                ["161650.65536", "1"],
                ["161650.65537", "65536"],
                ["161650.65538", "65536"],
                ["161650.131072", "1"],
                ["161650.131073", "131072"],
                ["161696.1", "0"],
                ["161696.65536", "1"],
                ["161696.65537", "65536"],
                ["161696.65538", "65536"],
                ["461883654.1", "0"],
                ["461883654.65536", "1"],
                ["461883654.65537", "65536"],
                ["461883654.65538", "65536"],
                ["461883654.131072", "1"],
                ["461883654.131073", "131072"],
                ["461883702.1", "0"],
                ["461883702.65536", "1"],
                ["461883702.65537", "65536"],
                ["461883702.65538", "65536"],
                ["461883702.131072", "1"],
                ["461883702.131073", "131072"],
                ["1261575062.1", "0"],
                ["1261575062.65536", "1"],
                ["1261575062.65537", "65536"],
                ["1261575062.65538", "65536"],
                ["1261575062.131072", "1"],
                ["1261575062.131073", "131072"],
                ["1530016262.1", "0"],
                ["1530016262.65536", "1"],
                ["1530016262.65537", "65536"],
                ["1530016262.65538", "65536"],
                ["1530016262.131072", "1"],
                ["1530016262.131073", "131072"],
                ["1530016278.1", "0"],
                ["1530016278.65536", "1"],
                ["1530016278.65537", "65536"],
                ["1530016278.65538", "65536"],
                ["1530016278.131072", "1"],
                ["1530016278.131073", "131072"],
                ["1530016294.1", "0"],
                ["1530016294.65536", "1"],
                ["1530016294.65537", "65536"],
                ["1530016294.65538", "65536"],
                ["1530016294.131072", "1"],
                ["1530016294.131073", "131072"],
                ["1530016310.1", "0"],
                ["1530016310.65536", "1"],
                ["1530016310.65537", "65536"],
                ["1530016310.65538", "65536"],
                ["1530016310.131072", "1"],
                ["1530016310.131073", "131072"],
                ["1530016324.1", "0"],
                ["1530016324.65536", "1"],
                ["1530016324.65537", "65536"],
                ["1530016324.65538", "65536"],
                ["1530016326.1", "0"],
                ["1530016326.65536", "1"],
                ["1530016326.65537", "65536"],
                ["1530016326.65538", "65536"],
                ["1530016326.131072", "1"],
                ["1530016326.131073", "131072"],
                ["1530016340.1", "0"],
                ["1530016340.65536", "1"],
                ["1530016340.65537", "65536"],
                ["1530016340.65538", "65536"],
                ["1530016342.1", "0"],
                ["1530016342.65536", "1"],
                ["1530016342.65537", "65536"],
                ["1530016342.65538", "65536"],
                ["1530016342.131072", "1"],
                ["1530016342.131073", "131072"],
                ["1530016372.1", "0"],
                ["1530016372.65536", "1"],
                ["1530016372.65537", "65536"],
                ["1530016372.65538", "65536"],
                ["1530016374.1", "0"],
                ["1530016374.65536", "1"],
                ["1530016374.65537", "65536"],
                ["1530016374.65538", "65536"],
                ["1530016374.131072", "1"],
                ["1530016374.131073", "131072"],
                ["1530016420.1", "0"],
                ["1530016420.65536", "1"],
                ["1530016420.65537", "65536"],
                ["1530016420.65538", "65536"],
                ["1530016422.1", "0"],
                ["1530016422.65536", "1"],
                ["1530016422.65537", "65536"],
                ["1530016422.65538", "65536"],
                ["1530016422.131072", "1"],
                ["1530016422.131073", "131072"],
                ["1530016438.1", "0"],
                ["1530016438.65536", "1"],
                ["1530016438.65537", "65536"],
                ["1530016438.65538", "65536"],
                ["1530016438.131072", "1"],
                ["1530016438.131073", "131072"],
                ["4219966596.1", "0"],
                ["4219966596.65536", "1"],
                ["4219966596.65537", "65536"],
                ["4219966598.1", "0"],
                ["4219966598.65536", "1"],
                ["4219966598.65537", "65536"],
                ["4219966598.65538", "65536"],
                ["4219966598.131072", "65536"],
                ["4219966598.196608", "131072"],
                ["4219966598.196609", "196608"],
                ["4219966598.196610", "196608"],
                ["4219966598.196611", "196608"],
                ["4219966598.262144", "131072"],
                ["4219966598.262145", "262144"],
                ["4219966598.262146", "262144"],
                ["4219966598.262147", "262144"],
                ["4219966598.327680", "131072"],
                ["4219966598.327681", "327680"],
                ["4219966614.1", "0"],
                ["4219966614.65536", "1"],
                ["4219966614.65537", "65536"],
                ["4219966614.65538", "65536"],
            ],
            [["826974748", "100"], ["891165643", "0"], ["898912908", "0"]],
            [["826974748", "1"], ["891165643", "0"], ["898912908", "0"]],
            [
                ["161650.1", "1"],
                ["161650.65536", "2"],
                ["161650.65537", "3"],
                ["161650.65538", "4"],
                ["161650.131072", "2"],
                ["161650.131073", "3"],
                ["161696.1", "1"],
                ["161696.65536", "2"],
                ["161696.65537", "3"],
                ["161696.65538", "7"],
                ["461883654.1", "1"],
                ["461883654.65536", "2"],
                ["461883654.65537", "3"],
                ["461883654.65538", "4"],
                ["461883654.131072", "2"],
                ["461883654.131073", "3"],
                ["461883702.1", "1"],
                ["461883702.65536", "2"],
                ["461883702.65537", "3"],
                ["461883702.65538", "4"],
                ["461883702.131072", "2"],
                ["461883702.131073", "3"],
                ["1261575062.1", "1"],
                ["1261575062.65536", "2"],
                ["1261575062.65537", "3"],
                ["1261575062.65538", "4"],
                ["1261575062.131072", "2"],
                ["1261575062.131073", "3"],
                ["1530016262.1", "1"],
                ["1530016262.65536", "2"],
                ["1530016262.65537", "3"],
                ["1530016262.65538", "4"],
                ["1530016262.131072", "2"],
                ["1530016262.131073", "3"],
                ["1530016278.1", "1"],
                ["1530016278.65536", "2"],
                ["1530016278.65537", "3"],
                ["1530016278.65538", "4"],
                ["1530016278.131072", "2"],
                ["1530016278.131073", "3"],
                ["1530016294.1", "1"],
                ["1530016294.65536", "2"],
                ["1530016294.65537", "3"],
                ["1530016294.65538", "4"],
                ["1530016294.131072", "2"],
                ["1530016294.131073", "3"],
                ["1530016310.1", "1"],
                ["1530016310.65536", "2"],
                ["1530016310.65537", "3"],
                ["1530016310.65538", "4"],
                ["1530016310.131072", "2"],
                ["1530016310.131073", "3"],
                ["1530016324.1", "1"],
                ["1530016324.65536", "2"],
                ["1530016324.65537", "3"],
                ["1530016324.65538", "7"],
                ["1530016326.1", "1"],
                ["1530016326.65536", "2"],
                ["1530016326.65537", "3"],
                ["1530016326.65538", "4"],
                ["1530016326.131072", "2"],
                ["1530016326.131073", "3"],
                ["1530016340.1", "1"],
                ["1530016340.65536", "2"],
                ["1530016340.65537", "3"],
                ["1530016340.65538", "7"],
                ["1530016342.1", "1"],
                ["1530016342.65536", "2"],
                ["1530016342.65537", "3"],
                ["1530016342.65538", "4"],
                ["1530016342.131072", "2"],
                ["1530016342.131073", "3"],
                ["1530016372.1", "1"],
                ["1530016372.65536", "2"],
                ["1530016372.65537", "3"],
                ["1530016372.65538", "7"],
                ["1530016374.1", "1"],
                ["1530016374.65536", "2"],
                ["1530016374.65537", "3"],
                ["1530016374.65538", "4"],
                ["1530016374.131072", "2"],
                ["1530016374.131073", "3"],
                ["1530016420.1", "1"],
                ["1530016420.65536", "2"],
                ["1530016420.65537", "3"],
                ["1530016420.65538", "7"],
                ["1530016422.1", "1"],
                ["1530016422.65536", "2"],
                ["1530016422.65537", "3"],
                ["1530016422.65538", "4"],
                ["1530016422.131072", "2"],
                ["1530016422.131073", "3"],
                ["1530016438.1", "1"],
                ["1530016438.65536", "2"],
                ["1530016438.65537", "3"],
                ["1530016438.65538", "4"],
                ["1530016438.131072", "2"],
                ["1530016438.131073", "3"],
                ["4219966596.1", "1"],
                ["4219966596.65536", "2"],
                ["4219966596.65537", "3"],
                ["4219966598.1", "1"],
                ["4219966598.65536", "2"],
                ["4219966598.65537", "3"],
                ["4219966598.65538", "6"],
                ["4219966598.131072", "1"],
                ["4219966598.196608", "2"],
                ["4219966598.196609", "3"],
                ["4219966598.196610", "7"],
                ["4219966598.196611", "4"],
                ["4219966598.262144", "2"],
                ["4219966598.262145", "3"],
                ["4219966598.262146", "7"],
                ["4219966598.262147", "4"],
                ["4219966598.327680", "2"],
                ["4219966598.327681", "3"],
                ["4219966614.1", "1"],
                ["4219966614.65536", "2"],
                ["4219966614.65537", "3"],
                ["4219966614.65538", "7"],
            ],
            [
                ["10201", "10000"],
                ["10202", "1000"],
                ["10501", "8000"],
                ["10502", "1000000000"],
                ["20506", "7666"],
                ["20509", "1000000000"],
                ["20510", "1000000000"],
                ["20511", "1000000000"],
                ["20512", "1000000000"],
                ["20513", "1000000000"],
                ["20514", "1000000000"],
                ["20516", "1000000000"],
                ["20517", "1000000000"],
                ["20518", "1000000000"],
                ["20519", "1000000000"],
                ["20582", "10000"],
                ["20583", "10000"],
            ],
        ]
    )


def test_discover_cisco_qos(section: Section) -> None:
    assert list(discover_cisco_qos(section)) == [
        Service(item="GigabitEthernet0/3: class-default"),
        Service(item="GigabitEthernet0/6: class-default"),
        Service(item="GigabitEthernet0/1.ServiceInstance.16: class-default"),
        Service(item="GigabitEthernet0/1.ServiceInstance.17: class-default"),
        Service(item="GigabitEthernet0/1.ServiceInstance.5: class-default"),
        Service(item="GigabitEthernet0/1.ServiceInstance.9: class-default"),
        Service(item="GigabitEthernet0/1.ServiceInstance.8: class-default"),
        Service(item="GigabitEthernet0/1.ServiceInstance.7: class-default"),
        Service(item="GigabitEthernet0/1.ServiceInstance.6: class-default"),
        Service(item="GigabitEthernet0/1.ServiceInstance.13: class-default"),
        Service(item="GigabitEthernet0/1.ServiceInstance.12: class-default"),
        Service(item="GigabitEthernet0/1.ServiceInstance.10: class-default"),
        Service(item="GigabitEthernet0/1.ServiceInstance.15: class-default"),
        Service(item="GigabitEthernet0/1.ServiceInstance.14: class-default"),
        Service(item="GigabitEthernet0/1.ServiceInstance.19: class-default"),
        Service(item="GigabitEthernet0/1.ServiceInstance.18: class-default"),
        Service(item="GigabitEthernet0/1.ServiceInstance.19: SCH_CL-VOIP"),
        Service(item="GigabitEthernet0/3: cos-zero"),
        Service(item="GigabitEthernet0/1.ServiceInstance.16: cos-zero"),
        Service(item="GigabitEthernet0/1.ServiceInstance.17: cos-zero"),
        Service(item="GigabitEthernet0/1.ServiceInstance.5: cos-zero"),
        Service(item="GigabitEthernet0/1.ServiceInstance.9: cos-zero"),
        Service(item="GigabitEthernet0/1.ServiceInstance.8: cos-zero"),
        Service(item="GigabitEthernet0/1.ServiceInstance.7: cos-zero"),
        Service(item="GigabitEthernet0/1.ServiceInstance.6: cos-zero"),
        Service(item="GigabitEthernet0/1.ServiceInstance.13: cos-zero"),
        Service(item="GigabitEthernet0/1.ServiceInstance.12: cos-zero"),
        Service(item="GigabitEthernet0/1.ServiceInstance.10: cos-zero"),
        Service(item="GigabitEthernet0/1.ServiceInstance.15: cos-zero"),
        Service(item="GigabitEthernet0/1.ServiceInstance.14: cos-zero"),
        Service(item="GigabitEthernet0/1.ServiceInstance.19: SCH_CL-OAM"),
    ]


@pytest.mark.parametrize(
    ["item", "params", "timestamp", "value_store", "expected_result"],
    [
        pytest.param(
            "GigabitEthernet0/1.ServiceInstance.16: class-default",
            {},
            100,
            {},
            [
                Result(state=State.OK, summary="Policy map name: queue-fix"),
                Result(state=State.OK, summary="Bandwidth: 100 kBit/s"),
            ],
            id="empty value store should not raise GetRateError",
        ),
        pytest.param(
            "GigabitEthernet0/1.ServiceInstance.16: class-default",
            {},
            100,
            {
                "qos_outbound_bits_rate": (50, 6728000000),
                "qos_dropped_bits_rate": (50, 0),
            },
            [
                Result(state=State.OK, summary="Outbound traffic: 31.3 kBit/s"),
                Metric("qos_outbound_bits_rate", 31288.32, boundaries=(0.0, 100000.0)),
                Result(state=State.OK, summary="Dropped traffic: 0.00 Bit/s"),
                Metric("qos_dropped_bits_rate", 0.0, boundaries=(0.0, 100000.0)),
                Result(state=State.OK, summary="Policy map name: queue-fix"),
                Result(state=State.OK, summary="Bandwidth: 100 kBit/s"),
            ],
            id="no thresholds",
        ),
        pytest.param(
            "GigabitEthernet0/6: class-default",
            {
                "post": (10000, 20000),
                "drop": (500, 750),
            },
            100,
            {
                "qos_outbound_bits_rate": (50, 27597768680),
                "qos_dropped_bits_rate": (50, 700007200),
            },
            [
                Result(
                    state=State.WARN,
                    summary="Outbound traffic: 19.4 kBit/s (warn/crit at 10.0 kBit/s/20.0 kBit/s)",
                ),
                Metric(
                    "qos_outbound_bits_rate",
                    19360.0,
                    levels=(10000.0, 20000.0),
                    boundaries=(0.0, 100000.0),
                ),
                Result(
                    state=State.CRIT,
                    summary="Dropped traffic: 900 Bit/s (warn/crit at 500 Bit/s/750 Bit/s)",
                ),
                Metric(
                    "qos_dropped_bits_rate",
                    899.84,
                    levels=(500.0, 750.0),
                    boundaries=(0.0, 100000.0),
                ),
                Result(state=State.OK, summary="Policy map name: 200Mbit"),
                Result(state=State.OK, summary="Bandwidth: 100 kBit/s"),
            ],
            id="absolute thresholds",
        ),
        pytest.param(
            "GigabitEthernet0/6: class-default",
            {
                "post": (10.0, 20.0),
                "drop": (1.0, 2.0),
                "unit": "byte",
            },
            100,
            {
                "qos_outbound_bits_rate": (50, 27597768680),
                "qos_dropped_bits_rate": (50, 700007200),
            },
            [
                Result(
                    state=State.WARN,
                    summary="Outbound traffic: 2.42 kB/s (warn/crit at 1.25 kB/s/2.50 kB/s)",
                ),
                Metric(
                    "qos_outbound_bits_rate",
                    19360.0,
                    levels=(10000.0, 20000.0),
                    boundaries=(0.0, 100000.0),
                ),
                Result(state=State.OK, summary="Dropped traffic: 112 B/s"),
                Metric(
                    "qos_dropped_bits_rate",
                    899.84,
                    levels=(1000.0, 2000.0),
                    boundaries=(0.0, 100000.0),
                ),
                Result(state=State.OK, summary="Policy map name: 200Mbit"),
                Result(state=State.OK, summary="Bandwidth: 12.5 kB/s"),
            ],
            id="relative thresholds, output in byte/s",
        ),
        pytest.param(
            "GigabitEthernet0/6: class-default",
            {
                "average": 10,
            },
            100,
            {
                "qos_outbound_bits_rate": (50, 27597768680),
                "qos_dropped_bits_rate": (50, 700007200),
                "qos_outbound_bits_rate.avg": (50, 80000),
                "qos_dropped_bits_rate.avg": (50, 1600),
            },
            [
                Result(state=State.OK, summary="Outbound traffic (10-min. average): 19.4 kBit/s"),
                Metric("qos_outbound_bits_rate", 19360.0, boundaries=(0.0, 100000.0)),
                Result(state=State.OK, summary="Dropped traffic (10-min. average): 900 Bit/s"),
                Metric("qos_dropped_bits_rate", 899.84, boundaries=(0.0, 100000.0)),
                Result(state=State.OK, summary="Policy map name: 200Mbit"),
                Result(state=State.OK, summary="Bandwidth: 100 kBit/s"),
            ],
            id="averaging",
        ),
        pytest.param(
            "GigabitEthernet0/6: class-default",
            {
                "average": 10,
                "post": (10.0, 20.0),
                "drop": (1.0, 2.0),
            },
            100,
            {
                "qos_outbound_bits_rate": (50, 27597768680),
                "qos_dropped_bits_rate": (50, 700007200),
                "qos_outbound_bits_rate.avg": (50, 80000),
                "qos_dropped_bits_rate.avg": (50, 800),
            },
            [
                Result(
                    state=State.WARN,
                    summary="Outbound traffic (10-min. average): 19.4 kBit/s (warn/crit at 10.0 kBit/s/20.0 kBit/s)",
                ),
                Metric(
                    "qos_outbound_bits_rate",
                    19360.0,
                    levels=(10000.0, 20000.0),
                    boundaries=(0.0, 100000.0),
                ),
                Result(state=State.OK, summary="Dropped traffic (10-min. average): 900 Bit/s"),
                Metric(
                    "qos_dropped_bits_rate",
                    899.84,
                    levels=(1000.0, 2000.0),
                    boundaries=(0.0, 100000.0),
                ),
                Result(state=State.OK, summary="Policy map name: 200Mbit"),
                Result(state=State.OK, summary="Bandwidth: 100 kBit/s"),
            ],
            id="averaging and thresholds",
        ),
    ],
)
def test_check_cisco_qos_(
    section: Section,
    item: str,
    params: Mapping[str, object],
    timestamp: float,
    value_store: Mapping[str, object],
    expected_result: CheckResult,
) -> None:
    assert (
        list(
            check_cisco_qos_(
                item=item,
                params=params,
                section=section,
                timestamp=timestamp,
                value_store=dict(value_store),
            )
        )
        == expected_result
    )


@pytest.fixture(name="section_zero_speed", scope="module")
def fixture_section_zero_speed() -> Section:
    return parse_cisco_qos(
        [
            [
                # ifs
                # [policy_id, iid2/if_id]
                ["7", "456"],
            ],
            [
                # policies
                # [policy_map_id, policy_name]
                ["123", "mypolicy"],
            ],
            [
                # classes
                # [class_id, cname]
                ["123", "c-out-q3"],
            ],
            [
                # config
                # [policy_id + . + objects_id, class_id/policy_map_id]
                # derives parent_value_cache: {"123": "0005"}
                # also contains b_key; value is used for lookup in qos_unit
                # and qos_bandwidth
                ["7.0005", "123"],
                ["999.9", "666"],
            ],
            [
                # post_bytes
                # [objects_id, post_b]
                ["7.0005", "0"],
            ],
            [
                # drop_bytes
                # [objects_id, drop_b]
                ["7.0005", "0"],
            ],
            [
                # if_names
                # [if_id, if_name]
                ["456", "QoS Ethernet1/8"],
            ],
            [
                # if_speeds
                # [if_id, speed]
                ["456", "4294967295"],
            ],
            [
                # parents
                # [class_id, objects_id]
                #  b_key     b_value
                ["999.9", "0005"],
            ],
            [
                # if_qos_bandwidth
                ["666", "100"],
            ],
            [
                # if_qos_bandwidth_units
                ["666", "3"],
            ],
            [
                # object_types
                # [policy_id or class_id, ? but needs to match 1 and 4 respectively]
                ["7.0005", "1"],
                ["999.9", "4"],
            ],
            [
                # high_speed
                # [if_id, speed]
                ["456", "10000"],
            ],
        ]
    )


@pytest.mark.parametrize(
    ["params", "expected_result"],
    [
        pytest.param(
            {
                "post": (0, 1),
                "drop": (0, 1),
            },
            [
                Result(
                    state=State.WARN,
                    summary="Outbound traffic: 0.00 Bit/s (warn/crit at 0.00 Bit/s/1.00 Bit/s)",
                ),
                Metric("qos_outbound_bits_rate", 0.0, levels=(0.0, 1.0), boundaries=(0.0, 0.0)),
                Result(
                    state=State.WARN,
                    summary="Dropped traffic: 0.00 Bit/s (warn/crit at 0.00 Bit/s/1.00 Bit/s)",
                ),
                Metric("qos_dropped_bits_rate", 0.0, levels=(0.0, 1.0), boundaries=(0.0, 0.0)),
                Result(state=State.OK, summary="Policy map name: mypolicy"),
                Result(state=State.OK, summary="Bandwidth: 0 Bit/s"),
            ],
            id="absolute thresholds => should apply",
        ),
        pytest.param(
            {
                "post": (0.0, 1.0),
                "drop": (0.0, 1.0),
            },
            [
                Result(state=State.OK, summary="Outbound traffic: 0.00 Bit/s"),
                Metric("qos_outbound_bits_rate", 0.0, boundaries=(0.0, 0.0)),
                Result(state=State.OK, summary="Dropped traffic: 0.00 Bit/s"),
                Metric("qos_dropped_bits_rate", 0.0, boundaries=(0.0, 0.0)),
                Result(state=State.OK, summary="Policy map name: mypolicy"),
                Result(state=State.OK, summary="Bandwidth: 0 Bit/s"),
            ],
            id="relative thresholds => do not apply",
        ),
    ],
)
def test_check_cisco_qos_zero_speed(
    section_zero_speed: Section,
    params: Mapping[str, object],
    expected_result: CheckResult,
) -> None:
    assert (
        list(
            check_cisco_qos_(
                item="QoS Ethernet1/8: c-out-q3",
                params=params,
                section=section_zero_speed,
                timestamp=100,
                value_store={
                    "qos_outbound_bits_rate": (60, 0),
                    "qos_dropped_bits_rate": (60, 0),
                },
            )
        )
        == expected_result
    )


@pytest.fixture(name="section_with_max_if_speed")
def fixture_section_with_max_if_speed() -> Section:
    return parse_cisco_qos(
        [
            [
                ["208", "13"],
                ["210", "13"],
                ["224", "14"],
                ["226", "14"],
                ["256", "16"],
                ["258", "16"],
                ["272", "17"],
                ["274", "17"],
                ["288", "18"],
                ["290", "18"],
                ["304", "19"],
                ["306", "19"],
            ],
            [
                ["57330033", "VLAN7"],
                ["57330035", "VLAN5"],
                ["57330036", "VLAN2"],
                ["57330037", "VLAN3"],
                ["57330046", "VLAN8"],
                ["57330047", "VLAN9"],
            ],
            [
                ["1593", "class-default"],
            ],
            [
                ["208.1", "57330036"],
                ["208.65536", "273238654"],
                ["208.65537", "566253201"],
                ["208.65538", "1619957463"],
                ["208.131072", "273238651"],
                ["208.131073", "623859479"],
                ["208.131074", "637940170"],
                ["208.131075", "1652674090"],
                ["208.196608", "1593"],
                ["208.196609", "1594"],
            ],
            [
                ["208.65536", "762918646"],
                ["208.131072", "1244206478"],
                ["208.196608", "1700796308"],
            ],
            [
                ["208.65536", "0"],
                ["208.131072", "1125701203"],
                ["208.196608", "0"],
            ],
            [
                ["13", "TenGigabitEthernet0/0/1.2"],
            ],
            [
                ["13", "4294967295"],
            ],
            [
                ["208.1", "0"],
                ["208.65536", "1"],
                ["208.65537", "65536"],
                ["208.65538", "65536"],
                ["208.131072", "1"],
                ["208.131073", "131072"],
                ["208.131074", "131072"],
                ["208.131075", "131072"],
                ["208.196608", "1"],
                ["208.196609", "196608"],
            ],
            [],
            [],
            [
                ["208.1", "1"],
                ["208.65536", "2"],
                ["208.65537", "3"],
                ["208.65538", "7"],
                ["208.131072", "2"],
                ["208.131073", "3"],
                ["208.131074", "3"],
                ["208.131075", "7"],
                ["208.196608", "2"],
                ["208.196609", "3"],
            ],
            [
                ["13", "10000"],
            ],
        ]
    )


@pytest.mark.parametrize(
    ["params", "expected_result"],
    [
        pytest.param(
            {},
            [
                Result(state=State.OK, summary="Outbound traffic: 340 MBit/s"),
                Metric("qos_outbound_bits_rate", 340159261.6, boundaries=(0.0, 10000000000.0)),
                Result(state=State.OK, summary="Dropped traffic: 0.00 Bit/s"),
                Metric("qos_dropped_bits_rate", 0.0, boundaries=(0.0, 10000000000.0)),
                Result(state=State.OK, summary="Policy map name: VLAN2"),
                Result(state=State.OK, summary="Bandwidth: 10 GBit/s"),
            ],
            id="maximum if_speed => use high_speed instead",
        ),
    ],
)
def test_check_cisco_qos_max_if_speed(
    section_with_max_if_speed: Section,
    params: Mapping[str, object],
    expected_result: CheckResult,
) -> None:
    assert (
        list(
            check_cisco_qos_(
                item="TenGigabitEthernet0/0/1.2: class-default",
                params=params,
                section=section_with_max_if_speed,
                timestamp=100,
                value_store={
                    "qos_outbound_bits_rate": (60, 0),
                    "qos_dropped_bits_rate": (60, 0),
                },
            )
        )
        == expected_result
    )
